<!--#
layout("/layouts/platform.html"){
#-->
<header class="header navbar bg-white shadow">
    <div class="btn-group tool-button">
        <a class="btn btn-primary navbar-btn" href="${base}/platform/cms/channel" data-pjax id="goback"><i class="ti-angle-left"></i> ${msg['globals.button.back']}</a>
    </div>
</header>

<div class="content-wrap">
    <div class="wrapper" style="min-height:500px;">
        <section class="panel panel-form">
            <form id="addForm" role="form" class="form-horizontal parsley-form" data-parsley-validate
                  action="${base}/platform/cms/channel/editDo" method="post">
                <input id="id" name="id" type="hidden" value="${obj.id!}">
                <input type="hidden" id="isShow" name="isShow" value="${obj.isShow!}">
                <input type="hidden" id="hasChildren" name="hasChildren" value="${obj.hasChildren!}">
                <div class="row mb10 mt10">
                    <div class="col-lg-12">
                        <div class="form-group has-feedback">
                            <label for="parentId" class="col-sm-2 control-label">${msg['cms.channel.column.upmenu']}</label>

                            <div class="col-sm-8">
                               <div class="input-group">
									<input id="parentId" type="text" class="form-control"
										placeholder="${msg['sys.dict.default']}" disabled
										value="<!--#if(!isEmpty(obj.parentId)){#-->${obj.parentId}<!--#}#-->" />

									<span class="input-group-btn">
										<button type="button" class="btn btn-primary"
											data-toggle="modal" data-target="#dialogSelectParentUnit">
											<i class="ti-plus"></i>${msg['cms.channel.column.selectmenu']}
										</button>
									</span>
								</div>
								<input type="hidden" name="parentId"
									value="<!--#if(!isEmpty(parentId)){#-->${parentId}<!--#}#-->">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="name" class="col-sm-2 control-label">${msg['cms.channel.column.columnname']}</label>

                            <div class="col-sm-8">
                                <input type="text" id="name" class="form-control" name="name" data-parsley-required="true"
                                       placeholder="${msg['cms.channel.column.columnname']}" value="${obj.name!}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="type" class="col-sm-2 control-label">${msg['cms.channel.column.columntype']}</label>

                            <div class="col-sm-8">
                                <select class="form-control" name="type" id="type">
                                    <option value="article" <!--#if(obj.type=="article"){#-->selected<!--#}#-->>${msg['cms.channel.column.article']}</option>
                                    <option value="photo"  <!--#if(obj.type=="photo"){#-->selected<!--#}#-->>${msg['cms.channel.column.photo']}</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="url" class="col-sm-2 control-label">${msg['cms.channel.column.urlpath']}</label>

                            <div class="col-sm-8">
                                <input type="text" id="url" name="url" class="form-control" placeholder="URL" value="${obj.url!}">

                            </div>
                        </div>
                        <div class="form-group">
                            <label for="target" class="col-sm-2 control-label">${msg['cms.channel.column.opentheway']}</label>

                            <div class="col-sm-8">
                                <select class="form-control" name="target" id="target">
                                    <option value="_self" <!--#if(obj.target=="_self"){#-->selected<!--#}#-->>${msg['cms.channel.column.thispage']}</option>
                                    <option value="_blank" <!--#if(obj.target=="_blank"){#-->selected<!--#}#-->>${msg['cms.channel.column.newpage']}</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="disabled" class="col-sm-2 control-label">${msg['cms.channel.column.isdisable']}</label>
                            <div class="col-sm-8 switcha">
                                <div class="mr15">
                                    <input type="checkbox" id="disabled" name="disabled"  <!--#if(obj.disabled){#-->checked<!--#}#--> class="js-switch-blue" >
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-3"></div>
                    <div class="col-lg-6">
                        <div class="form-group text-center">
                            <label></label>

                            <div>
                                <button id="save" TYPE="button" class="btn btn-primary btn-block btn-lg btn-parsley" data-loading-text="${msg['cms.channel.column.nowsubmit']}正在提交...">${msg['cms.channel.column.submit']}提 交</button>
                            </div>
                        </div>
                    </div>
            </form>
        </section>

    </div>
</div>
<a class="exit-offscreen"></a>
<!-- 选择上级单位 -->
<div id="dialogSelectParentUnit" class="modal fade bs-modal-sm"
	tabindex="-1" role="dialog" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-hidden="true">×</button>
				<h4 class="modal-title">${msg['cms.channel.column.selectmenu']}</h4>
			</div>
			<div class="modal-body">
				<div class="row">
					<div class="col-xs-12">
						<div id="jsTreeParentUnit" class="demo"></div>
					</div>
				</div>
			</div>
			<div class="modal-footer">
				<div class="pull-left">
					<button type="button" class="btn btn-success" data-dismiss="modal"
						onclick="selectFirstMenu()">${msg['cms.channel.column.settop']}</button>
				</div>
				<button type="button" class="btn btn-default" data-dismiss="modal">${msg['cms.channel.column.cancel']}</button>
				<button type="button" class="btn btn-primary"
					onclick="selectParentMenu()">${msg['cms.channel.column.selectok']}</button>
			</div>
		</div>
	</div>
</div>
<script language="JavaScript">
    $(document).ready(function () {
        myForm.init();
        //图标样式 实时预览
        $("input[name=homepage]").on("change", function(){
            if('true'==$(this).val()){
                $("#div").show();
            }else{
                $("#div").hide();
            }
        });
        $("#save").on("click",function(){
            $('#addForm').submit();
        });
        $('#addForm').ajaxForm({
            dataType: 'json',
            beforeSubmit: function (arr, form, options) {
                form.find("button:submit").button("loading");
            },
            success: function (data, statusText, xhr, form) {
                if (data.code==0) {
                    Toast.success(data.msg);
                    setTimeout(function () {
                        $("#goback").trigger("click");
                    }, 1000);
                } else {
                    Toast.error(data.msg);
                }
                form.find("button:submit").button("reset");
            }
        });
    });

    function initTreeView() {
        $("#jsTreeParentUnit").jstree({
            plugins: ["wholerow", "json_data"],
            core: {
                data: {
                    dataType: "json",
                    url: function (node) {
                        return node.id === "#" ? "${base}/platform/cms/channel/tree" : "${base}/platform/cms/channel/tree/" + node.id
                    }
                },
                multiple: false
            }
        }).on("dblclick.jstree", function (node) {
            selectParentMenu();
        });
    }
    
    
    
  //选择父菜单
    function selectParentMenu() {
        var tree = $.jstree.reference("#jsTreeParentUnit");
        var node = tree.get_selected(true);
        $("#addForm #parentId").val(node[0].text);
        $("#addForm input[name='parentId']").val(node[0].id);
        $("#dialogSelectParentUnit").modal("hide");
    }
    function selectFirstMenu() {
        $("#addForm #parentId").val("顶级");
        $("#addForm input[name='parentId']").val("");
        $("#dialogSelectParentUnit").modal("hide");
    }
    $(document).ready(function () {
        initTreeView();
        $('#addForm').ajaxForm({
            dataType: 'json',
            beforeSubmit: function (arr, form, options) {
                form.find("button:submit").button("loading");
            },
            success: function (data, statusText, xhr, form) {
                if (data.code==0) {
                    Toast.success(data.msg);
                    //刷新父级菜单
                    $.jstree.reference("#jsTreeParentUnit").refresh();
                    var parentName = $("#addForm #parentId").val();
                    form.resetForm();
                    $("#addForm #parentId").val(parentName);
                } else {
                    Toast.error(data.msg);
                }
                form.find("button:submit").button("reset");
            }
        });
    });
    
</script>

<!--#}#-->